import React, { Component } from 'react';
import { Modal, message, Col, Row, Tag } from 'antd';

export default class SetReboot extends Component {
  state = {
    confirmLoading: false,
  };
  handleSet = () => {
    this.setState({
      confirmLoading: true,
    });
    const { selectedRows, dispatch } = this.props;
    const devIds = selectedRows.join(',');

    dispatch({
      type: 'dev/setReboot',
      payload: { devIds },
      callback: () => {
        //
        message.success('重启设备成功.');
        //this.setState({ confirmLoading: false });
      },
    });
    this.props.handleModalVisible(false);
  };

  render() {
    const { selectedRows } = this.props;
    const { modalVisible, handleModalVisible } = this.props;
    const { confirmLoading } = this.state;
    return (
      <Modal
        title="确定重启下列设备么"
        visible={modalVisible}
        onOk={this.handleSet}
        confirmLoading={this.state.confirmLoading}
        onCancel={() => handleModalVisible(false)}
      >
        <Row style={{ width: '100%' }}>
          {selectedRows.map(item => (
            <Col span={8}>
              <Tag>{item}</Tag>
            </Col>
          ))}
        </Row>
      </Modal>
    );
  }
}
